package com.jhhc.StormSurgeForecast.Calculate.util;


import java.io.File;
import java.util.List;

/**
 * @author
 * 下载文件
 */
public class DownloadUtil {

    /**
     * 下载GWPstas.dat文件
     * @param downloadUrl 下载链接
     * @param token token
     * @param linuxPath 远程路径
     * @param localPath 下载到本地的路径
     */
    public boolean downloadGwpstas(String downloadUrl, String token, String linuxPath, String localPath){
        CalUtil calUtil = new CalUtil();
        linuxPath = linuxPath + "GWPstas.dat";
        localPath = localPath + File.separator + "GWPstas.dat";
        return calUtil.fileDownload(downloadUrl,token,linuxPath,localPath);
    }


    /**
     * 下载fort.61文件
     * @param downloadUrl 下载链接
     * @param token token
     * @param linuxPath 远程路径
     * @param localPath 下载到本地的路径
     */
    public boolean downloadFort61(String downloadUrl, String token, String linuxPath, String localPath){
        CalUtil calUtil = new CalUtil();
        linuxPath = linuxPath + "fort.61";
        localPath = localPath + File.separator + "fort.61";
        return calUtil.fileDownload(downloadUrl,token,linuxPath,localPath);
    }
    /**
     * 下载fort.63文件
     * @param downloadUrl 下载链接
     * @param token token
     * @param linuxPath 远程路径
     * @param localPath 下载到本地的路径
     */
    public boolean downloadFort63(String downloadUrl, String token, String linuxPath, String localPath){
        CalUtil calUtil = new CalUtil();
        linuxPath = linuxPath + "/fort.63";
        localPath = localPath + File.separator + "fort.63";
        return calUtil.fileDownload1(downloadUrl,token,linuxPath,localPath);
    }

    /**
     * 下载BTFUP文件
     * @param downloadUrl 下载链接
     * @param token token
     * @param linuxPaths 远程路径
     * @param localPath 下载到本地的路径
     */
    public void downloadBtfup(String downloadUrl, String token, List<String> linuxPaths, String localPath){
        CalUtil calUtil = new CalUtil();
        String fileName;
        String filePath;
        for (String linuxPath : linuxPaths) {
            int index = linuxPath.lastIndexOf("/");
            fileName = linuxPath.substring(index + 1);
            filePath = localPath + File.separator + fileName;
            calUtil.fileDownload(downloadUrl, token, linuxPath, filePath);
        }
    }

    /**
     * 下载fort.64文件
     * @param downloadUrl 下载链接
     * @param token token
     * @param linuxPath 远程路径
     * @param localPath 下载到本地的路径
     */
    public boolean downloadFort64(String downloadUrl, String token, String linuxPath, String localPath){
        CalUtil calUtil = new CalUtil();
        linuxPath = linuxPath + "/fort.64";
        localPath = localPath + File.separator + "fort.64";
        return calUtil.fileDownload1(downloadUrl,token,linuxPath,localPath);
    }

    /**
     *下载surge_output.dat文件
     * @param downloadUrl 下载链接
     * @param token token
     * @param linuxPath 远程路径
     * @param localPath 下载到本地的路径
     */
    public String downloadSurgeOutput(String downloadUrl, String token, String linuxPath, String localPath){
        CalUtil calUtil = new CalUtil();
        linuxPath = linuxPath + "surge_output.dat";
        localPath = localPath + File.separator + "surge_output.dat";
        calUtil.fileDownload(downloadUrl,token,linuxPath,localPath);//下载
        return localPath;
    }
    /**
     *下载tide_output.dat文件
     * @param downloadUrl 下载链接
     * @param token token
     * @param linuxPath 远程路径
     * @param localPath 下载到本地的路径
     */
    public String downloadTideOutput(String downloadUrl, String token, String linuxPath, String localPath){
        CalUtil calUtil = new CalUtil();
        linuxPath = linuxPath + "tide_output.dat";
        localPath = localPath + File.separator + "tide_output.dat";
        calUtil.fileDownload(downloadUrl,token,linuxPath,localPath);//下载

        return localPath;
    }
    /**
     *下载Stormtide_output.dat文件
     * @param downloadUrl 下载链接
     * @param token token
     * @param linuxPath 远程路径
     * @param localPath 下载到本地的路径
     */
    public String downloadStormtideOutput(String downloadUrl, String token, String linuxPath, String localPath){
        CalUtil calUtil = new CalUtil();
        linuxPath = linuxPath + "Stormtide_output.dat";
        localPath = localPath + File.separator + "Stormtide_output.dat";
        calUtil.fileDownload(downloadUrl,token,linuxPath,localPath);//下载
        return localPath;
    }
    /**
     *下载tfupresuls.dat文件
     * @param downloadUrl 下载链接
     * @param token token
     * @param linuxPath 远程路径
     * @param localPath 下载到本地的路径
     */
    public boolean downloadTfupresuls(String downloadUrl, String token, String linuxPath, String localPath){
        CalUtil calUtil = new CalUtil();
        linuxPath = linuxPath + "tfupresuls.dat";
        localPath = localPath + File.separator + "tfupresuls.dat";
        return calUtil.fileDownload(downloadUrl,token,linuxPath,localPath);
    }
}
